<!-- 可编辑单元格组件 -->
<template>
    <div class="editable-cell-main">
        <div v-if="editable" class="editable-cell-input-wrapper">
            <div v-if="col=='classMethod'">
                <!--分类名称-->
                <a-select @change="handleSelectChange" @blur="handleSelectBlur" :defaultOpen="true" ref="focusid">
                    <a-select-option value="1" label="">
                        记账凭证
                    </a-select-option>
                    <a-select-option value="2" label="">
                        收付转
                    </a-select-option>
                    <a-select-option value="3" label="">
                        现银转
                    </a-select-option>
                    <a-select-option value="4" label="">
                        现现银银转
                    </a-select-option>
                    <a-select-option value="5" label="">
                        自定义
                    </a-select-option>
                </a-select>
            </div>

            <div v-else-if="col=='limitType'">
                <!--限制类型-->
                <a-select @change="handleSelectChange" @blur="handleSelectBlur" :defaultOpen="true" ref="focusid">
                    <a-select-option value="1" label="">
                        无限制
                    </a-select-option>
                    <a-select-option value="2" label="">
                        借方必有
                    </a-select-option>
                    <a-select-option value="3" label="">
                        贷方必有
                    </a-select-option>
                    <a-select-option value="4" label="">
                        凭证必无
                    </a-select-option>
                    <a-select-option value="5" label="">
                        凭证必有
                    </a-select-option>
                    <a-select-option value="6" label="">
                        借方必无
                    </a-select-option>
                    <a-select-option value="7" label="">
                        贷方必无
                    </a-select-option>
                </a-select>
            </div>

            <div v-else-if="col=='accountingName'">
                <!--限制科目-->
                <searchGroupDetail ref="searchComponents" :record="record" :inputValue="text" :componentName="componentName" @clickItem="searchBackData"></searchGroupDetail>
            </div>
            <div v-else-if="col=='classWord'">
                <!--凭证字-->
                <a-input :value="value" ref="focusid" maxLength="2" @change="handleChange" @pressEnter="check" @blur="checkClose" />
            </div>
            <a-input v-else :value="value" ref="focusid" @change="handleChange" @pressEnter="check" @blur="checkClose" />
        </div>
        <div v-else class="editable-cell-text-wrapper" @click="edit" style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
            <!--分类名称-->
            <!-- 1记账凭证2:收付转3:现银转4:现现银银转5:自定义 -->
            <div v-if="col=='classMethod'">{{ value == 1?'记账凭证':value == 2?'收付转':value==3?'现银转':value==4?'现现银银转':value==5?'自定义':'' }}</div>
            <!--限制类型-->
            <!-- 1无限制2:借方必有3:贷方必有4:凭证必无5:凭证必有6:借方必无7:贷方必无 -->
            <div v-else-if="col=='limitType'">{{ value == 1?'无限制':value == 2?'借方必有':value==3?'贷方必有':value==4?'凭证必无':value==5?'凭证必有':value==6?'借方必无':value==7?'贷方必无':'' }}</div>

            <div v-else style="padding:0 2px;">{{ value || '&nbsp;' }}</div>
        </div>
    </div>
</template>
<script>

import getDate from "@/utils/tool/date";
import moment from "moment";
import searchGroupDetail from "@/components/PopUpLayer/searchGroupDetail";  //静态表格明细搜索组
import { searchCheckBoxArchives } from "@/components/PopUpLayer";           //物料多选组件

export default {
    components: {
        searchGroupDetail,
        searchCheckBoxArchives
    },
    props: {
        text: String,
        record: {
            type: Object,
            default: () => { }
        },
        col: {
            type: String
        },
        //物料类型
        checkType: { 
            type: Array,
            default: () => []
        },
    },
    data() {
        return {
            value: this.text,
            editable: false,
            componentName: '',      //组件名
            processMethod: '',      //加工方式
            workFlag: '',            //工序标识
        };
    },
    mounted() {

    },
    created() {

    },
    watch: {
        processMethod(val) {
            console.log(`selected:`, val);
        },
    },
    methods: {
        moment,
        closeModel() {
            //关闭弹出层
            const closesModel = document.getElementById('closesModel');
            closesModel.addEventListener('click', (e) => {
                this.editable = false;
                this.archivesCheck();
            }, false)
        },
        //==========================默认输入框==========================
        handleChange(e) {
            const value = e.target.value;
            this.value = value;

            this.$emit("change", this.value, 'input');
        },
        checkClose() {
            this.editable = false;
        },
        check() {
            this.editable = false;
            this.$emit("change", this.value);
        },
        handleSelectChange(value, label) {
            this.editable = false;
            this.value = label.componentOptions.children[0].text;
            this.$emit("change", value);
        },
        //==========================默认输入框==========================
        handleSelectBlur() {
            this.editable = false;
        },
        edit() {
            console.log(this.col, this.text);
            this.editable = true;
            // if (this.col == 'teamName') {
            //     //班组
            //     this.componentName = 'team';
            // } else if (this.col == 'workName' || this.col == 'workCode') {
            //     //工序名称
            //     console.log(this.text);
            //     this.componentName = 'process';
            //     this.$nextTick(() => {
            //         this.$refs.searchComponents.showModal();
            //     })
            // } else if (this.col == 'bomVersion') {
            //     //子件bom
            //     this.componentName = 'bomVersion';
            //     this.$nextTick(() => {
            //         this.$refs.searchComponents.showModal();
            //     })
            // } else if (this.col == 'workerName') {
            //     //工人
            //     console.log('工人：', this.text);
            //     this.componentName = 'workerName';
            //     this.$nextTick(() => {
            //         this.$refs.searchComponents.showModal();
            //     })
            // } else if (this.col == 'inventoryCode' || this.col == 'inventoryName') {
            //     //子件编码||子件名称
            //     this.$nextTick(() => {
            //         this.closeModel();
            //     })
            // } else {
            if (this.col == 'accountingName') {
                this.componentName = 'accounting';
                this.$nextTick(() => {
                    this.$refs.searchComponents.showModal();
                })
            } else {
                this.$nextTick(() => {
                    this.$refs.focusid.focus();
                });
            }
        },
        searchBackData(record) {
            this.editable = false;
            if (record) {
                console.log(record.constructor, record)
                if (record.constructor === Object || record.constructor === Array) {
                    this.value = record.name;
                    this.$emit("change", record);
                }
            } else {
                this.$emit("change");
            }
        },
    },
};
</script>
<style lang="less">
#closesModel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 82;
    background: rgba(255, 255, 255, 0);
}
.editable-cell-main {
    position: relative;
    height: 30px;
    line-height: 30px;
    width: 100%;
    margin: 0 auto;
    cursor: pointer;
    .ant-input {
        height: 30px;
        text-align: left;
        font-size: 13px;
        padding: 0;
        border: 1px solid #000 !important;
    }
    .ant-select-selection--single {
        height: 28px !important;
    }
    .ant-select-selection {
        border: 1px solid #000 !important;
    }

    .editable-cell-input-wrapper {
        padding: 0;
    }
    .editable-cell-text-wrapper {
        padding: 0 2px;
        height: 100%;
        width: 100%;
    }
    .editable-cell-icon,
    .editable-cell-icon-check {
        position: absolute;
        right: 0;
        width: 20px;
        cursor: pointer;
    }

    .editable-cell-icon {
        line-height: 18px;
        display: none;
    }

    .editable-cell-icon-check {
        line-height: 28px;
    }

    .editable-cell:hover .editable-cell-icon {
        display: inline-block;
    }

    .editable-cell-icon:hover,
    .editable-cell-icon-check:hover {
        color: #108ee9;
    }

    .editable-add-btn {
        margin-bottom: 8px;
    }

    .editable-cell-input-search {
        position: relative;
    }

    .ant-input {
        border: none;
        border-bottom: 1px solid #a0a0a0;
        border-radius: 0;
    }
    .ant-select-selection,
    .ant-input:focus {
        box-shadow: none;
    }

    .ant-select {
        width: 100%;
        height: 100%;
    }
    .ant-select-selection {
        border-radius: 0px;
    }
}
</style>